package com.mjf.ys.util;


import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @author zzz
 **/
@Component
public class HttpClientConfig {
    /**
     * 读取超时.
     */
    private static final Integer READ_TIME = 180000;

    /**
     * 链接超时.
     */
    private static final Integer CONNECT_TIME = 3000;

    /**
     * amwayRestTemplate
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public RestTemplate amwayRestTemplate() {
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        // 5S读取超时
        factory.setReadTimeout(READ_TIME);
        // 3S链接超时
        factory.setConnectTimeout(CONNECT_TIME);
        return new RestTemplate(factory);
    }
}
